import React from 'react';
import { Table, Button } from 'antd';
import { connect } from 'dva';
import Title from '../Title';
import { timeFormat } from '@/utils/common';
const BackLog = ({ unDoList, dispatch }) => {
  const columns = [
    { title: '待办事项', dataIndex: 'content' },
    { title: '发起人', dataIndex: 'from' },
    {
      title: '接收时间',
      dataIndex: 'createTime',
      render: text => timeFormat(text, 'YYYY-MM-DD hh:mm:ss'),
    },
    { title: '办理类型', dataIndex: 'handType' },
    {
      title: '操作',
      width: 225,
      render: (text, data) => (
        <Button onClick={() => goDetail(data)} type="link">
          办理
        </Button>
      ),
    },
  ];
  const getUrl = ({ type, uuid }) => {
    const approveUrl = {
      PLAN: `declareManage/planManage/edit?id=${uuid}&readOnly=true&fromType=3&isApprove=true`,
      ANNUAL: `projectApprove/yearProjectApprove/edit?id=${uuid}&readOnly=true&fromType=1&isApprove=true`,
      MONEY: `projectFillIn/money/edit?id=${uuid}&readOnly=true&fromType=7&isApprove=true`,
    };
    return approveUrl[type];
  };
  const goDetail = data => {
    const url = getUrl(data);
    dispatch({
      type: '$router/forward',
      payload: { url },
    });
  };

  return (
    <div style={{ width: '100%', padding: '0 24px' }}>
      <Title title={`待我办理（${unDoList.totalCount}）`} />
      <Table
        columns={columns}
        dataSource={unDoList.dataList}
        pagination={false}
        style={{ width: '100%' }}
      />
    </div>
  );
};

export default connect(state => state.home)(BackLog);
